/**
 * 
 */
package org.t2.game.server.foundation.ssh;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

/**
 * 
 */
public class SshConnection {
	private String user = "root";
	private String password = "Wt12345678";
	private String host = "8.134.48.121";
	private int port = 22;
	
	private String remoteHost = "127.0.0.1";
	private int remotePort = 3306;
	
	//本地转发端口
	private int localPort = 3308;
	
	private Session session;
	
	
	public void connect() {
		JSch jsch = new JSch();
		try {
			session = jsch.getSession(user, host, port);
			session.setPassword(password);
			session.setConfig("StrictHostKeyChecking", "no");
			session.connect();
			session.setPortForwardingL(localPort, remoteHost, remotePort);
		} catch (JSchException e) {
			e.printStackTrace();
		}
	}
	
	public void close() {
		session.disconnect();
	}
}
